//
//  RFChoice2ViewController.m
//  HeadYang
//
//  Created by sunmingming on 15/8/3.
//  Copyright (c) 2015年 xiaoluoli. All rights reserved.
//

#import "RFChoice2ViewController.h"
#import "RFChoice3ViewController.h"

@interface RFChoice2ViewController ()

@property(nonatomic,assign) BOOL isMan;
@property(nonatomic,assign) int longType;//0-long 1-middle 2-short

-(IBAction)manPressed:(id)sender;
-(IBAction)womanPressed:(id)sender;

-(IBAction)longPressed:(id)sender;
-(IBAction)middlePressed:(id)sender;
-(IBAction)shortPressed:(id)sender;

-(IBAction)nextPressed:(id)sender;

@property(nonatomic,weak) IBOutlet UILabel *sexLabel;
@property(nonatomic,weak) IBOutlet UIButton *longButton;
@property(nonatomic,weak) IBOutlet UIButton *middleButton;
@property(nonatomic,weak) IBOutlet UIButton *shortButton;
@property(nonatomic,weak) IBOutlet UIImageView *longImage;
@property(nonatomic,weak) IBOutlet UIImageView *middleImage;
@property(nonatomic,weak) IBOutlet UIImageView *shortImage;
@property(nonatomic,weak) IBOutlet UIImageView *longDg;
@property(nonatomic,weak) IBOutlet UIImageView *middleDg;
@property(nonatomic,weak) IBOutlet UIImageView *shortDg;

@end

@implementation RFChoice2ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"头发类型";
        self.navigationItem.leftBarButtonItem =
        [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrow_white"]
                                         style:UIBarButtonItemStyleDone
                                        target:self
                                        action:@selector(backPressed:)];
    }
    return self;
}

-(void)backPressed:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewDidLoad {
    [super viewDidLoad];
    self.isMan = YES;
    self.longType = 0;
    [self sexChanged];
    [self longChanged];
}

-(void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)manPressed:(id)sender{
    self.isMan = YES;
    [self sexChanged];
}

-(IBAction)womanPressed:(id)sender{
    self.isMan = NO;
    [self sexChanged];
}

-(IBAction)longPressed:(id)sender{
    self.longType = 0;
    [self longChanged];
}
-(IBAction)middlePressed:(id)sender{
    self.longType = 1;
    [self longChanged];
}
-(IBAction)shortPressed:(id)sender{
    self.longType = 2;
    [self longChanged];
}

-(void)sexChanged{
    if(self.isMan){
        self.sexLabel.backgroundColor = [UIColor blueColor];
        [self.longButton setBackgroundImage:[UIImage imageNamed:@"select_back_male.png"] forState:UIControlStateNormal];
        [self.middleButton setBackgroundImage:[UIImage imageNamed:@"select_back_male.png"] forState:UIControlStateNormal];
        [self.shortButton setBackgroundImage:[UIImage imageNamed:@"select_back_male.png"] forState:UIControlStateNormal];
        [self.longImage setImage:[UIImage imageNamed:@"male_hair_long.png"]];
        [self.middleImage setImage:[UIImage imageNamed:@"male_hair_mid.png"]];
        [self.shortImage setImage:[UIImage imageNamed:@"male_hair_short.png"]];
    }else{
        self.sexLabel.backgroundColor = [UIColor redColor];
        [self.longButton setBackgroundImage:[UIImage imageNamed:@"select_back_female.png"] forState:UIControlStateNormal];
        [self.middleButton setBackgroundImage:[UIImage imageNamed:@"select_back_female.png"] forState:UIControlStateNormal];
        [self.shortButton setBackgroundImage:[UIImage imageNamed:@"select_back_female.png"] forState:UIControlStateNormal];
        [self.longImage setImage:[UIImage imageNamed:@"female_hair_long.png"]];
        [self.middleImage setImage:[UIImage imageNamed:@"female_hair_mid.png"]];
        [self.shortImage setImage:[UIImage imageNamed:@"female_hair_short.png"]];
    }
}

-(void)longChanged{
    if(0 == self.longType){
        self.longDg.hidden = NO;
        self.middleDg.hidden = YES;
        self.shortDg.hidden = YES;
    }else if(1 == self.longType){
        self.longDg.hidden = YES;
        self.middleDg.hidden = NO;
        self.shortDg.hidden = YES;
    }else if(2 == self.longType){
        self.longDg.hidden = YES;
        self.middleDg.hidden = YES;
        self.shortDg.hidden = NO;
    }
}

-(IBAction)nextPressed:(id)sender{
    APPALL.myGender = self.isMan?@"男":@"女";
    if(self.longType == 0)
        APPALL.myHairType = @"长发";
    if(self.longType == 1)
        APPALL.myHairType = @"中发";
    if(self.longType == 2)
        APPALL.myHairType = @"短发";
    RFChoice3ViewController *vc = [RFChoice3ViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
